home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DDJMAG / DDJ8801.ZIP / NARO.ZIP / LOCATE.C < prev    next >
Text File  |  1987-10-30  |  4KB  |  150 lines

  1. /*
  2.     Copyright (C) 1987 Paradigm Systems Inc.  All rights reserved.
  3. */
  4.  
  5. #include    <stdio.h>
  6. #include    <stdlib.h>
  7. #include    <string.h>
  8. #include    <signal.h>
  9.  
  10. #include    "loc.h"
  11. #include    "globals.h"
  12. #include    "externs.h"
  13.  
  14. /*
  15.     LOCATE *** MS-DOS ROM Utility
  16.     Copyright (C) 1987 Paradigm Systems, Inc.  All rights reserved.
  17.  
  18.     This version is released in the public domain and may not be sold.
  19. */
  20.  
  21. int    main(argc, argv)
  22. int argc;
  23. char *argv[];
  24. {
  25.     char    *s, *input_file ;
  26.     unsigned char    *entry_point ;
  27.     int    i ;
  28.  
  29.     /*
  30.         This is the root module of the locate utility and it controls the
  31.         sequencing of the entire location process.
  32.     */
  33.  
  34.     /* Install a Control-C interrupt handler */
  35.     if (signal(SIGINT, break_handler) == (int(*)()) -1)   {
  36.         fprintf(stderr, "Failure to install break handler\n") ;
  37.         abort() ;
  38.     }
  39.  
  40.     /* Build a command line string using argv[0] through argv[argc-1] */
  41.     command_line[0] = '\0' ;
  42.     for (i = 0; i < argc; i++)   {
  43.         strcat(command_line, argv[i]) ;
  44.         strcat(command_line, " ") ;
  45.     }
  46.  
  47.     /* Test if the user needs help in running this utility */
  48.     if (argc == 1)
  49.         help = TRUE ;
  50.  
  51.     config_fname[0] = abs_fname[0] = print_fname[0] = '\0' ;
  52.     
  53.     /* Process each argument in sequence until all are processed */
  54.     while (--argc > 0 && (*++argv)[0] == '-')   {
  55.         for (s = argv[0] + 1;  *s != '\0';  s++)   {
  56.             switch (*s)   {
  57.                 case 'b':
  58.                     boot_rec = TRUE ;
  59.                     break ;
  60.  
  61.                 case 'c':
  62.                     config = TRUE ;
  63.                     if (*++s)
  64.                         strcpy(config_fname, s) ;
  65.                     *s-- = '\0' ;
  66.                     break ;
  67.  
  68.                 case 'h':
  69.                     hex_name = TRUE ;
  70.                     if (*++s)
  71.                         strcpy(abs_fname, s) ;
  72.                     *s-- = '\0' ;
  73.                     break ;
  74.  
  75.                 default:
  76.                     help = TRUE ;
  77.                     argc = 0 ;
  78.                     break ;
  79.             }
  80.         }
  81.     }
  82.     input_file = argv[0] ;
  83.  
  84.     if (help == TRUE)   {
  85.         fprintf(stderr, "\nUsage is\n\n") ;
  86.         fprintf(stderr, "\tlocate switches exefile\n\n") ;
  87.         fprintf(stderr, "The valid switches are:\n\n") ;
  88.         fprintf(stderr, "\t%-14s create bootstrap record\n", "-b") ;
  89.         fprintf(stderr, "\t%-14s configuration filename\n", "-c[name]") ;
  90.         fprintf(stderr, "\t%-14s hex filename\n", "-h[name]") ;
  91.         exit(1) ;
  92.     }
  93.  
  94.     fprintf(stderr, "                 MS-DOS Locate Utility - Version 1.0A\n") ;
  95.     fprintf(stderr, "        Copyright (C) 1987 Paradigm Systems Inc.  ") ;
  96.     fprintf(stderr, "All rights reserved.\n\n") ;
  97.     fprintf(stderr, "Public Domain Software courtesy of\n") ;
  98.     fprintf(stderr, "        Paradigm Systems, Inc.\n        P.O. Box 152\n") ;
  99.     fprintf(stderr, "        Milford, MA 01757\n\n") ;
  100.  
  101.     /* Open and create the files used in the location process */
  102.     open_file_system(input_file) ;
  103.     
  104.     /* Install the routine to shutdown the utility gracefully in the
  105.         event of an error. */
  106.     onexit(close_file_system) ;
  107.  
  108.     /* Build the segment descriptor list using the link map */
  109.     seg_list = build_seg_list();
  110.  
  111.     /* Process the locate configuration file */
  112.     if (process_locate_file(seg_list) == ERROR)   {
  113.         fprintf(stderr, "Error(s) reading the locate map\n") ;
  114.         exit(1) ;
  115.     }
  116.  
  117.     /* Convert any public symbols to their new physical addresses */
  118.     read_symbol_table(seg_list) ;
  119.     
  120.     /* Read the load module and perform the segment fixups */
  121.     entry_point = load_exe_file() ;
  122.  
  123.     /* Add a bootstrap record if enabled on the command line */
  124.     if (boot_rec == TRUE)
  125.         create_bootstrap(seg_list, entry_point) ;
  126.  
  127.     /* Output the load module in the specified format */
  128.     output_hex_OMF(abs_file, seg_list, entry_point) ;
  129.  
  130.     /* Make the locate map containing the new segment assignments */
  131.     print_statistics(map_fname, print_fname, command_line, exe_fname, \
  132.         abs_fname, config_fname, entry_point) ;
  133.  
  134.     exit(0) ;
  135. }
  136.  
  137.  
  138. void    break_handler()
  139. {
  140.     /*
  141.         The break handler is provided to catch Ctrl-C interrupts from the
  142.         user and perform a shutdown of the program in a graceful manner.
  143.     */
  144.         
  145.     /* Set the user abort flag for the file system close routine */
  146.     user_abort = TRUE ;
  147.     exit(1) ;
  148. }
  149.  
  150.